import re
from flask import Blueprint, jsonify, request

from app import LogService
from utils import create_response, StateCode

id_card_bp = Blueprint('id_card_server', __name__)


@id_card_bp.route('/id_card/verify', methods=['POST'])
def idCardVerify():
    pattern = r'^\d{18}$'
    id_number = request.json.get('idCardNo')
    state = {
        "result": bool(re.match(pattern, id_number))
    }
    LogService.log()
    return jsonify(create_response(StateCode.SUCCESS, data=state)), 200
